Skip to content

Conversation

krgjert
Copy link
Member

@krgjert krgjert commented Nov 11, 2026

Purpose

Allow database initialization and reseeding to be rerun safely without deleting existing published builds.

Changes

  • Use IF NOT EXISTS when creating the builds table.
  • Replace TRUNCATE with a temporary import table and upsert components by ID.
  • Preserve existing builds and components missing from the CSV.
  • Run initialization and seeding in one transaction, stopping on errors.
  • Validate DATABASE_URL and document reseeding in README.

Related issues

Closes #91

Verification

Manually tested on local PostgreSQL 16.15:

  • Initial setup imported 800 components.
  • Running bash backend/db/seed.sh again succeeded.
  • Reseeding preserved an existing build and its CPU reference.
  • A modified price was restored from the CSV, with 800 components remaining.
  • A deliberate SQL error rolled back the transaction, preserving the previous price.

No automated tests were added; verification used a separate local test database.

Screenshots

Not applicable.

Checklist

  • I have reviewed my own changes.
  • The changes meet the linked issue's acceptance criteria, where applicable.
  • I have verified the changes and recorded the results above.
  • I have added or updated tests where needed.
  • I have updated documentation where needed.
  • I have included screenshots for visual changes, or marked them not applicable.

@krgjert krgjert added the enhancement New feature or request label Nov 11, 2026
@krgjert krgjert added this to the 4. underveisinnlevering milestone Nov 11, 2026
@krgjert krgjert self-assigned this Nov 11, 2026
@krgjert krgjert requested a review from a team as a code owner November 11, 2026 18:58
@krgjert krgjert linked an issue Nov 11, 2026 that may be closed by this pull request
4 tasks
Copy link
Member

@wilhelsr wilhelsr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Nice improvements to database seeding and data preservation.

@wilhelsr wilhelsr merged commit b33e845 into main Nov 12, 2026
@krgjert krgjert deleted the 91-fix-database-initialization-and-seeding branch November 14, 2026 09:30
Sign in to join this conversation on GitHub.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix database initialization and seeding
2 participants